package cn.com.dbappsecurity.model;

import java.io.IOException;
import java.util.List;

import org.apache.log4j.Logger;

import cn.com.dbappsecurity.utils.LocaleUtil;
import freemarker.template.TemplateMethodModel;
import freemarker.template.TemplateModelException;

public class LocaleModal implements TemplateMethodModel{

	private static final Logger LOG = Logger.getLogger(LocaleModal.class);
	
	private String language;
	
	public LocaleModal(String language){
		this.language = language;
	}
	
	@SuppressWarnings("rawtypes")
	@Override
	public Object exec(List args) throws TemplateModelException {
		String message = null;
		if(args != null && args.size() > 0){
			try {
				message = LocaleUtil.getMessage(args.get(0).toString(),language);
			} catch (IOException e) {
				LOG.error("读取资源文件出错",e);
			}
		}
		return message == null ? "" : message;
	}

}
